import re


class Coordinate:
    """时间紧，就没写注释了"""
    DIGIT = re.compile(r'(\d+)')

    def __init__(self, x=0, y=0):
        self._x = x
        self._y = y
        if not getattr(__class__, 'maps', None):
            setattr(__class__, 'maps', {
                'W': self.up,
                'A': self.left,
                'S': self.down,
                'D': self.right,
            })

    def right(self, sep: int = 0):
        if sep < 0:
            raise ValueError("sep must > 0")
        self._x += sep

    def left(self, sep: int = 0):
        if sep < 0:
            raise ValueError("sep must > 0")
        self._x -= sep

    def up(self, sep: int = 0):
        if sep < 0:
            raise ValueError("sep must > 0")
        self._y += sep

    def down(self, sep: int = 0):
        if sep < 0:
            raise ValueError("sep must > 0")
        self._y -= sep

    def origin(self):
        self._x = 0
        self._y = 0

    def move(self, step=""):
        move_sep = step.upper().split(';')
        for sep in move_sep:
            if len(sep) and sep[0] in 'WASD':
                pattern = self.DIGIT.match(sep[1:])
                if pattern and pattern.group() == sep[1:]:
                    self.move_sep(sep[0], sep[1:])

    @staticmethod
    def move_sep(direct, sep):
        getattr(__class__, 'maps').get(direct)(int(sep))

    def show(self):
        print(self._x, self._y)


if __name__ == '__main__':
    cc = Coordinate()
    cc.move('A10;S20;W10;D30;X;A1A;B10A11;;A10;')
    cc.show()
    # 写的很不错~
